﻿using EWms.WebApi;
using Serilog;
using Serilog.Events;

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Diagnostics", LogEventLevel.Error)
.MinimumLevel.Override("Quartz", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Async(c => c.File("logs/all/log-.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Debug))
.WriteTo.Async(c => c.File("logs/error/errorlog-.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Error))
.WriteTo.Async(c => c.Console())
.CreateLogger();


try
{
    Log.Information("""


     _____                  __        __ __  __  ____  
    | ____| __ _  ___  _   _\ \      / /|  \/  |/ ___| 
    |  _|  / _` |/ __|| | | |\ \ /\ / / | |\/| |\___ \ 
    | |___| (_| |\__ \| |_| | \ V  V /  | |  | | ___) |
    |_____|\__,_||___/ \__, |  \_/\_/   |_|  |_||____/   {Version}  
                       |___/                            


    """, "Version: 1.0");
    Log.Information($"EasyWMS，启动！ ");

    var builder = WebApplication.CreateBuilder(args);
    Log.Information($"当前主机启动环境-【{builder.Environment.EnvironmentName}】");
    Log.Information($"当前主机启动地址-【{builder.Configuration["SelfUrl"]}】");
    builder.AddServices();
    var app = builder.Build();
    app.UseMiddlewares();
    await app.RunAsync();
}
catch (Exception ex)
{
    Log.Fatal(ex, "EasyWMS，爆炸💥！");
}
finally
{
    Log.CloseAndFlush();
}
